﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace GreatB2C.Web.Manage
{
    public partial class Login : Inherit.PageBase
    {
        protected void Page_Load( object sender , EventArgs e )
        {
            if ( !IsPostBack )
            {
                Response.Expires = 0;
                Response.CacheControl = "no-cache";
                //Logout( );
                //string TmUrl = Request.QueryString[ "urls" ];
                //if ( TmUrl != null && TmUrl != "" )
                //{
                //    string tmDir = GreatB2C.Config.SiteInfo.UIConfig.dirMana.Trim( ) + "/index.aspx";
                //    string tmDir1 = GreatB2C.Config.SiteInfo.UIConfig.dirMana.Trim( ) + "/menu.aspx";
                //    if ( ( TmUrl.ToString( ).ToLower( ) ).IndexOf( tmDir.ToLower( ) ) == -1 && ( TmUrl.ToString( ).ToLower( ) ).IndexOf( tmDir1.ToLower( ) ) == -1 ) { this.HidUrl.Value = TmUrl.ToString( ); }
                //}
                //string[] _protPass = GreatB2C.Config.SiteInfo.UIConfig.protPass.Split( ',' );
                //if ( _protPass[ 0 ] == "1" ) { safeCodeVerify_1.Visible = true; }
                //else { safeCodeVerify_1.Visible = false; }
            }
        }


        protected void login_Click( object sender , ImageClickEventArgs e )
        {
            if ( Page.IsValid )
            {
                //string Account = this.TxtName.Text;
                //string PassWord = this.TxtPassword.Text;
                //string VerifyCode = this.TxtVerify.Text.Trim( );
                //string SafeCode = this.TxtSafeCode.Text;
                //string Urls = this.HidUrl.Value;
                //if ( Account.Trim( ) == string.Empty || PassWord.Trim( ) == string.Empty )
                //{
                //    PageError( "用户与密码不能为空,详细请查看帮助说明!" , "login.aspx?" + Request.QueryString );
                //}
                //if ( Session[ "CheckCode" ] == null )
                //{
                //    PageError( "验证码过期，请返回重新登录!" , "login.aspx?" + Urls + "" );
                //}
                //string CheckCode = Session[ "CheckCode" ].ToString( ).ToUpper( );
                //Session.Remove( "CheckCode" );
                //if ( VerifyCode.ToUpper( ) != CheckCode )
                //{
                //    PageError( "输入验证码错误!" , "login.aspx?" + Urls + "" );
                //}
                #region 安全码验证
                //string[] _protPass = GreatB2C.Config.SiteInfo.UIConfig.protPass.Split( ',' );
                //if ( _protPass[ 0 ] == "1" )
                //{
                //    if ( _protPass[ 1 ] == "1" )
                //    {
                //        if ( _protPass[ 2 ] == "0" )
                //        {
                //            if ( ( VerifyCode + GreatB2C.Config.SiteInfo.UIConfig.protRand( ) ) != SafeCode )
                //            {
                //                PageError( "输入的安全码错误!" , "login.aspx?" + Urls + "" );
                //            }
                //        }
                //        else
                //        {
                //            if ( ( GreatB2C.Config.SiteInfo.UIConfig.protRand( ) + VerifyCode ) != SafeCode )
                //            {
                //                PageError( "输入的安全码错误!" , "login.aspx?" + Urls + "" );
                //            }
                //        }
                //    }
                //    else
                //    {
                //        if ( GreatB2C.Config.SiteInfo.UIConfig.protRand( ) != SafeCode )
                //        {
                //            PageError( "输入的安全码错误!" , "login.aspx?" + Urls + "" );
                //        }
                //    }
                //}
                #endregion 安全码验证

                //GlobalUserInfo info;
                //EnumLoginState state = Login( Account , PassWord , out info , true );
                //if ( state == EnumLoginState.Succeed )
                //{
                //    GreatB2C.Global.Current.Set( info );
                //    if ( Urls != null && Urls.Trim( ) != string.Empty )
                //    {
                //        string MangeStr = GreatB2C.Config.SiteInfo.UIConfig.dirMana + "/index.aspx".ToLower( );
                //        if ( Urls.IndexOf( MangeStr ) > 0 )
                //        {
                //            Response.Write( "<script language=\"javascript\">window.top.location.href=\"Index.aspx\";</script>" );
                //            Response.End( );
                //        }
                //        else
                //        {
                //            Response.Write( "<script language=\"javascript\">window.top.location.href=\"Index.aspx?urls=" + Urls + "\";</script>" );
                //            Response.End( );
                //        }
                //    }
                //    else
                //    {
                Response.Write( "<script language=\"javascript\">window.top.location.href=\"Index.aspx\";</script>" );
                Response.End( );
                //    }
                //}
                //else
                //{
                //    LoginResultShow( state );
                //}
            }
        }


    }
}
